package org.learn.tankgame5;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Scanner;

public class QjjTankGame05 extends JFrame {

    //定义一个MyPanel
    MyPanel mp = null;
    static  Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {


        QjjTankGame05 qjjTankGame01 = new QjjTankGame05();
    }
    public QjjTankGame05(){
        System.out.println("请输入选择 1 ：新游戏 2 ：继续上局");
        String key = scanner.next();
        //初始化面板
        mp = new MyPanel(key);
        //将mp放到Thread ，并启动；
        Thread thread = new Thread(mp);
        thread.start();

        //把面板放入画框(窗口)
        this.add(mp);
        //设置窗口大小
        this.setSize(1300,950);
        this.addKeyListener(mp);//监听mp键盘事件
        this.setVisible(true);//可视
        //点击窗口的红叉程序完全退出
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        //在JFrame 中增加相应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                try {
                    Recorder.keepRecord();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
                System.exit(0);
            }
        });

    }
}
